<template>
  <div>
    <el-table
      :data="goodArr"
      style="width: 100%"
      row-key="id"
      border
      :lazy="true"
      :default-expand-all="false"
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="分类编号" width="180">
      </el-table-column>
      <el-table-column prop="catename" label="分类名称"> </el-table-column>
      <el-table-column label="图片">
        <template slot-scope="obj">
          <img :src="$imgHost + obj.row.img" alt="" />
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="obj">
          <el-button type="success" v-if="obj.row.status == 1" round
            >启用</el-button
          >
          <el-button type="danger" v-else round>禁用</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="obj">
          <el-button
            type="primary"
            icon="el-icon-edit"
            circle
            @click="updataCate(obj.row.id)"
          ></el-button>
          <el-button type="danger" icon="el-icon-delete" circle @click="delCate(obj.row.id)"></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {cateDelete} from '../../request/api.js'
import { successMsg, failedMsg } from "../../tools/tools.js";
export default {
  props: ["goodArr"],
  methods: {
    updataCate(id) {
      this.$emit("updataCate", id);
    },
    delCate(id){
      this.$confirm("此操作将永久删除, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          cateDelete({ id })
            .then((d) => {
              if (d.data.code == 200) {
                //删除成功
                successMsg("删除成功");
                     this.$emit("updataList")
         
              }
            })
            .catch((e) => {
              console.log(e);
            });
        })
        .catch((e) => {});
    }
  },
};
</script>

<style scoped>
.el-table img {
  width: 100px;
}
</style>